package com.aipanda.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

/**
 * 发货点类
 * 
 * @param name 发货中心名称
 * @param contact 联系人
 * @param areaName 区域名称
 * @param address 地址
 * @param zipCode 邮编
 * @param phone 电话
 * @param mobile 手机
 * @param memo 备注
 * @param isDefault 是否默认
 * @param area 区域
 * @author wanyuxiang
 * 
 */
@Entity
@Table(name = "aipanda_delivery_center")
public class DeliveryCenter extends BaseEntity {
	private static final long serialVersionUID = 3328996121729039075L;
	private String name;
	private String contact;
	private String areaName;
	private String address;
	private String zipCode;
	private String phone;
	private String mobile;
	private String memo;
	private Boolean isDefault;
	private Area area;

	@NotEmpty
	@Length(max = 255)
	@Column(nullable = false)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@NotEmpty
	@Length(max = 255)
	@Column(nullable = false)
	public String getContact() {
		return this.contact;
	}

	public void setContact(String contact) {
		this.contact = contact;
	}

	@Column(name="area_name",nullable = false)
	public String getAreaName() {
		return this.areaName;
	}

	public void setAreaName(String areaName) {
		this.areaName = areaName;
	}

	@NotEmpty
	@Length(max = 255)
	@Column(nullable = false)
	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Length(max = 255)
	@Column(name="zip_code")
	public String getZipCode() {
		return this.zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

	@Length(max = 255)
	public String getPhone() {
		return this.phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Length(max = 255)
	public String getMobile() {
		return this.mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	@Length(max = 255)
	public String getMemo() {
		return this.memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	@NotNull
	@Column(name="is_default",nullable = false)
	public Boolean getIsDefault() {
		return this.isDefault;
	}

	public void setIsDefault(Boolean isDefault) {
		this.isDefault = isDefault;
	}

	@NotNull
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="area")
	public Area getArea() {
		return this.area;
	}

	public void setArea(Area area) {
		this.area = area;
	}

	public DeliveryCenter prePersist(DeliveryCenter deliveryCenter) {
		if (deliveryCenter.getArea() != null){
			deliveryCenter.setAreaName(deliveryCenter.getArea().getFullName());
		}
		return deliveryCenter;
	}

	public DeliveryCenter preUpdate(DeliveryCenter deliveryCenter) {
		if (deliveryCenter.getArea() != null){
			deliveryCenter.setAreaName(deliveryCenter.getArea().getFullName());
		}
		return deliveryCenter;
	}
}
